package a_doubleWrite;

/**
 * todo
 *
 * @author luolidong
 * @version 1.0
 * @create 2021-07-28 19:42
 */
public class L152 {
    public int maxProduct(int[] nums) {
        if (nums == null) return 0;
        if (nums.length == 1) return nums[0];
        int[] min_dp = new int[nums.length + 1];
        int[] max_dp = new int[nums.length + 1];
        max_dp[0] = 1;
        min_dp[0] = 1;
        int ans = 0;
        for (int i = 1; i <= nums.length; i++) {
            //还要比较他自己
            max_dp[i] = Math.max(nums[i-1],Math.max(nums[i - 1] * max_dp[i - 1], nums[i - 1] * min_dp[i - 1]));
            min_dp[i] = Math.min(nums[i-1],Math.min(nums[i - 1] * max_dp[i - 1], nums[i - 1] * min_dp[i - 1]));
            ans = Math.max(ans, max_dp[i]);
        }
        return ans;
    }
}
